package com.gm.baseplatform.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gm.baseplatform.base.cfg.Configuration;
import com.gm.baseplatform.base.module.Module;
import com.gm.baseplatform.core.utils.ObjectUtil;

public class ResourceCachePool {

	private  Map<String,Configuration> configCache = 
		 new HashMap<String,Configuration>();
	
	private  Map<Module,List<?>> moduleTreeCache =
		new HashMap<Module,List<?>>();
	
	public void cacheConfig(List<?> configs) {
		
		if (ObjectUtil.isNull(configs) || configs.isEmpty()) {
			return;
		}
		
		for (int i = 0,j = configs.size(); i < j; i++) {
			Configuration config = (Configuration)configs.get(i);
			configCache.put(config.getName(),config);
		}
	}
	
	public Configuration getConfigCacheByName(String name) {
		return configCache.get(name);
	}
	
	public void cacheModuleTree(Map<Module,List<?>> moduleTree) {
		
		if (ObjectUtil.isNull(moduleTree) || moduleTree.isEmpty()) {
			return;
		}
		
		moduleTreeCache = moduleTree;
	}
	
	public Map<Module,List<?>> getModuleTreeCache() {
		return moduleTreeCache;
	}
}
